<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class BWebshopEmailReceiverBean {
	
	public function __construct() {
	// contructor function
	}
	
	/*	get all user to add to email receiver
	 */ 
	public static function get_all_user_email($db) {
        $strSQL = sprintf("SELECT * FROM ".TBL_USER." u ".
						  " WHERE NOT EXISTS(SELECT * FROM ".TBL_EMAIL_RECEIVER." e WHERE e.user_id = u.user_id) ");
        return $db->get_results($strSQL);
    } 
	
	
	 /*	get all email receiver 
	 */
	public static function get_all_email($db) {
		
    	$strSQL = sprintf("SELECT * FROM ".TBL_EMAIL_RECEIVER." e ".
						  "LEFT JOIN ".TBL_USER." u ON u.user_id=e.user_id");
    	return $db->get_results($strSQL);
    }
	
	 public static function save_email_receiver($db, $id) {
    	$strSQL = sprintf("INSERT INTO %s (user_id) VALUES ('%s')",TBL_EMAIL_RECEIVER,$id);
    	$res = $db->query($strSQL);
    	if($res == true) {
    		return $db->insert_id;
    	} else
    		return -1;
    }
	
	 public static function delete_email_receiver_by_id($db, $id) {
    	$strSQL = sprintf("DELETE FROM %1\$s " .
    			"WHERE id='$id'", TBL_EMAIL_RECEIVER);
    	$res = $db->query($strSQL);
    	
    	return $res;
    }
	
}
?>
